/**
 * Copyright By Nanjing Fujitsu Nanda Software Technology Co., Ltd
 * 上午11:33:46
 * EvaluationInfoException.java
 * 
 */
package com.fujitsu.nanjing.mobile.exception;

import java.util.ArrayList;

import javax.xml.namespace.QName;
import javax.xml.soap.SOAPException;
import javax.xml.soap.SOAPFactory;
import javax.xml.soap.SOAPFault;
import javax.xml.ws.WebFault;
import javax.xml.ws.soap.SOAPFaultException;

/**
 * @author qixb.fnst
 * 
 */
@WebFault(faultBean = "com.yicai.gardenexposition.exception.WebServiceFault", name = "WebServiceException", targetNamespace = "http://service.zljk.scs.niit.edu.cn/")
public class WebServcieException extends Exception {

	/**
	 * 
	 */
	private static final long serialVersionUID = 1L;
	private WebServiceFault faultInfo;
	/**
	 * @param info
	 */
	public WebServcieException(WebServiceFault info) {
		super();
		this.setFaultInfo(info);
	}
	/**
	 * 
	 */
	public WebServcieException() {
		super();
		this.setFaultInfo(new WebServiceFault());
	}
	public WebServcieException(int errorCode, String errorString) {
        this(String.valueOf(errorCode), new String[]{errorString});

    }
	public WebServcieException(String errorCode, String errorString) {
		this(errorCode, new String[]{errorString});

	}
	public WebServcieException(String errorCode, String[] errorStrings) {
		super();
		this.faultInfo = new WebServiceFault(errorCode);
		if (errorStrings != null) {
			if (this.faultInfo.getErrorStrings() == null) {
				this.faultInfo.setErrorStrings(new ArrayList<String>());
			}
			for (String errorString : errorStrings) {
				this.faultInfo.getErrorStrings().add(errorString);
			}
		}

	}
	public WebServcieException(String message, WebServiceFault faultInfo) {
		super(message);
		this.faultInfo = faultInfo;

	}
	/**
	 * @return the faultInfo
	 */
	public WebServiceFault getFaultInfo() {
		return faultInfo;
	}
	/**
	 * @param faultInfo
	 *            the faultInfo to set
	 */
	public void setFaultInfo(WebServiceFault faultInfo) {
		this.faultInfo = faultInfo;
	}

	@Override
	public Throwable getCause() {
		SOAPFault fault;
		try {
			fault = SOAPFactory.newInstance().createFault();
			fault.setFaultCode(new QName(this.getFaultInfo().getErrorCode()));
			fault.setFaultString(this.getFaultInfo().toString());
			SOAPFaultException ex = new SOAPFaultException(fault);

			return ex;
		} catch (SOAPException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
			return super.getCause();
		}
	}

}
